const edge = require("edge");
const fs = require("fs");
const path = require("path");
var InvokeRuleIsNormal = edge.func({
	assemblyFile: path.join(__dirname, "bin/ForEdge.dll"),
	typeName: "ForEdge.Startup",
	methodName: "InvokeRuleIsNormal"
});

const rule = (module.exports = {});
[
	"Straight",
	"Flush",
	"StraightFlush",
	"Five",
	"Four",
	"Three",
	"Two",
	"TwoPair",
	"FullHouse"
].forEach(method_name => {
	var prop_name =
		"is" +
		method_name.replace(/[A-Z]/g, function(v) {
			return "_" + v.toLowerCase();
		});
	rule[prop_name] = function(card_list, res_info, len = 5) {
		return new Promise((resolve, reject) => {
			InvokeRuleIsNormal(
				{
					card_list: card_list,
					method_name: method_name,
					s_len: len
				},
				function(err, res) {
					if (err) {
						reject(err);
					} else {
						resolve(res.Is);
						if (res_info) {
							Object.assign(res_info, res.res_info);
						}
					}
				}
			);
		});
	};
});
